import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

/** @type {import('eslint').Linter.Config[]} */
export default [
	{
		files: ["**/*.{js,mjs,cjs,ts,vue}"],
		settings: {
			"import/extensions": [".js", ".jsx", "ts", "tsx", "vue"],
			"import/resolver": {
				node: {
					extensions: [".js", ".jsx", ".ts", ".tsx"], // 配置文件扩展名
				},
				// 配置alias
				alias: {
					map: [["@/", "./src"]],
					extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
				},
			},
		},
	},
	{
		languageOptions: {
			globals: globals.browser,
		},
	},
	{
		extends: ["auto-imports.d.ts"],
	},
	pluginJs.configs.recommended,
	...tseslint.configs.recommended,
	...pluginVue.configs["flat/essential"],
	/**
	 * vue 规则
	 */
	{
		files: ["**/*.vue"],
		languageOptions: {
			parserOptions: {
				/** typescript项目需要用到这个 */
				parser: tseslint.parser,
				ecmaVersion: "latest",
				/** 允许在.vue 文件中使用 JSX */
				ecmaFeatures: {
					jsx: true,
				},
			},
		},
		rules: {
			// 在这里追加 vue 规则
			"vue/no-mutating-props": [
				"error",
				{
					shallowOnly: true,
				},
			],
		},
	},
	// eslintConfigPrettier,
	/**
	 * prettier 配置
	 * 会合并根目录下的prettier.config.js 文件
	 * @see https://prettier.io/docs/en/options
	 */
	eslintPluginPrettierRecommended,
];
